package cn.edu.neusoft.zengweidong707.neufood.fragment;

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cn.edu.neusoft.zengweidong707.neufood.R;
import cn.edu.neusoft.zengweidong707.neufood.adapter.ShopListAdapter;
import cn.edu.neusoft.zengweidong707.neufood.bean.ShopListBean;
import cn.edu.neusoft.zengweidong707.neufood.listener.ListListener;
import cn.edu.neusoft.zengweidong707.neufood.model.UserModel;

/**
 * shop_id:店铺ID
 * phonenum:订餐电话
 * intro:店铺简介
 * comment:备注
 */

public class ShopFragment extends BaseFragment {
    private UserModel model;
    private RecyclerView recyclerView;
    private List<ShopListBean> list;
    private ListListener listListener;
    private ShopListAdapter shopListAdapter;
    private LinearLayoutManager linearLayoutManager;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        setLayout_file(R.layout.fragment_shoplist);
        listListener = new ListListener<ShopListBean>() {
            @Override
            public void onResponse(List<ShopListBean> shopListBeans) {
                list = shopListBeans;
                shopListAdapter = new ShopListAdapter(getActivity(), list);
                recyclerView.setAdapter(shopListAdapter);
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
            }
        };
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    void initView() {
            recyclerView = (RecyclerView)view.findViewById(R.id.recycleview);
            linearLayoutManager = new LinearLayoutManager(getActivity());
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(linearLayoutManager);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    void initEvent() {

    }

    @Override
    void initData() {
        model = new UserModel();
        model.getShopList(listListener);
    }

    public ShopFragment() {

    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }

}
